package com.pingsky.apm.agent.core.trace;

import com.pingsky.apm.network.language.agent.v1.PSpan;

import java.util.List;

public class TraceSpan {
    private int spanId;
    private int parentSpanId;
    private long startTime;
    private long endTime;
    private String operationName;
    private int componentId;
    private TraceException exception;
    private List<TagValuePair> tags;
    private boolean error;

    public PSpan build() {
        PSpan.Builder spanBuilder = PSpan.newBuilder()
                .setSpanId(spanId)
                .setParentSpanId(parentSpanId)
                .setStartTime(startTime)
                .setEndTime(endTime)
                .setOperationName(operationName)
                .setComponentId(componentId)
                .setException(exception.build())
                .setIsError(error);

        if (null != tags) {
            for (TagValuePair tag : tags) {
                spanBuilder.addTags(tag.build());
            }
        }
        return spanBuilder.build();
    }
}
